{extend name="public:layout" /}
{block name="title"}附件管理{/block}
{block name="head"}{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('index')}"> 附件管理</a></li>
                <li class="active">附件列表</li>
            </ol>
        </div>
        <div class="ibox-content">
            <div class="col-sm-3">
                <div class="toolbar">
                    <button type="button" onclick="addGroup();" class="btn btn-info">添加分组</button>
                </div>
                <table class="table">
                    <tr {eq name="vo.group_id" value="$query['group_id']"}class="active"{/eq}>
                        <td><a href="{:url('index')}">未分组</a></td>
                        <td width="100">#</td>
                    </tr>
                    {volist name="groupList" id="vo"}
                    <tr {eq name="vo.group_id" value="$query['group_id']"}class="active"{/eq}>
                    <td><a href="{:url('index',['group_id'=>$vo['group_id']])}">{$vo.group_name}</a></td>
                    <td width="100">
                        <a href="javascript:;" onclick="editGroup(this)" data-groupname="{$vo.group_name}" data-url="{:url('editGroup',['group_id'=>$vo['group_id']])}">编辑</a>
                        <a href="javascript:;" onclick="doAction(this);"
                           data-msg="确认删除吗？" data-url="{:url('delGroup')}" data-params="group_id={$vo.group_id}">删除</a>
                    </td>
                    </tr>
                    {/volist}
                </table>
            </div>
            <div class="col-sm-9">
                <div class="toolbar">
                    <div class="pull-left">
                        <button type="button" onclick="CheckAll();" class="btn btn-white">全</button>
                        <button type="button" onclick="CheckOther();" class="btn btn-white">反</button>
                        <button type="button" onclick="batchDel(CheckboxValue())" class="btn btn-danger">
                            <i class="fa fa-trash"></i> 删除
                        </button>
                        <select id="groupId" class="form-control pull-right" style="width:120px;">
                            <option value="0">未分组</option>
                            {volist name="groupList" id="vo"}
                            <option value="{$vo.group_id}">{$vo.group_name}</option>
                            {/volist}
                        </select>
                        <button type="button" onclick="moveGroup(CheckboxValue());" class="btn btn-info pull-right">移动到</button>
                    </div>
                    <div class="pull-right">
                        <div class="info pull-left" style="padding-top:8px;padding-right:15px;"></div>
                        <div id="filePicker1" class="pull-left">上传图片</div>
                        <div id="filePicker2" class="pull-left" style="margin-left:10px;">上传附件</div>
                        <div class="clearfix"></div>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <table class="table table-bordered" id="grid">
                    <thead>
                    <tr>
                        <th width="50">#</th>
                        <th width="80">附件</th>
                        <th>上传</th>
                        <th>大小</th>
                        <th>文件名</th>
                        <th>类型</th>
                        <th>上传时间</th>
                        <th width="120">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="list" id="vo"}
                    <tr>
                        <td>
                            <input name="id[]" type="checkbox" class="checkbox" value="{$vo.id}">
                        </td>
                        <td class="text-center">{$vo.url_text}</td>
                        <td>{$vo.upload_type}</td>
                        <td>{:get_file_size($vo['size'])}</td>
                        <td>{$vo.title}</td>
                        <td>{$vo.type}</td>
                        <td>{$vo.mtime|date="Y-m-d H:i",###}</td>
                        <td>
                            <a href="javascript:;" onclick="doAction(this);"
                               data-msg="确认删除吗？" data-url="{:url('del')}" data-params="id={$vo.id}">删除</a>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
                <div class="page-bar">{$list->render()}</div>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        uploadOnePic('filePicker1','{$uid}',function(res){
            rePage();
        });
        uploadOneFile('filePicker2','{$uid}',function(res){
            rePage();
        });
    });
    //批量删除
    function batchDel(ids) {
        if (IsMore(ids)) {
            var url = "{:url('del')}";
            var params = {'id': ids};
            doConfirm('你确认要删除吗？', url, params, function (data) {
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 800}, function () {
                        rePage();
                    });
                }
            });
        }
    }
    
    //添加分组
    function addGroup() {
        In('layer',function(){
            layer.prompt({formType: 0, title: '请输入分组名'},function(val, index){
                getAjax("{:url('addGroup')}",{group_name:val},function(res){
                    if(res.code==1){
                        rePage();
                    }else{
                        layer.alert(res.msg);
                    }
                });
                layer.close(index);
            });
        })
    }
    //移动分组
    function moveGroup(ids) {
        if (IsMore(ids)) {
            var groupId = $('#groupId').val();
            var url = "{:url('moveGroup')}";
            var params = {'ids': ids,'group_id':groupId};
            doConfirm('你确认要移动选择附件吗？', url, params, function (data) {
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 800}, function () {
                        rePage();
                    });
                }
            });
        }
    }
    function editGroup(obj) {
        var groupName = $(obj).data('groupname');
        var url = $(obj).data('url');
        In.use('layer',function(){
            layer.prompt({formType: 0, title: '修改分组名',value:groupName},function(val, index){
                getAjax(url,{group_name:val},function(res){
                    if(res.code==1){
                        rePage();
                    }else{
                        layer.alert(res.msg);
                    }
                });
                layer.close(index);
            });
        })
    }
</script>
{/block}